from app.services.business.gaolu_diagnose.ind.abstract_ind import AbstractInd


class CG_LT_GL_GL04_Zha_CaO_1(AbstractInd):
    def get_name(self):
        return "CG_LT_GL_GL04_Zha_CaO_1"

    def get_data_source(self):
        return "mysql"

    def get_sql(self, params):
        sql_Zha_CaO_1 = """   
        select round(avg(jyh.jyjg),3) as CG_LT_GL_GL04_Zha_CaO_1 
        from 
        (select jyh.*,jyt.ph, tqpd.tjsj
        from syn_zl_zl_jyh as jyh ,syn_zl_zl_jyt as jyt ,syn_zl_zl_tqpd as tqpd
        where  jyh.jcxmbm='01010' and jyh.zfbz='0' 
        and jyt.wlbm = 'ZJ003' 
        and SUBSTRING(jyt.ph, 4, 1) = '4' 
        and  jyt.jytid = jyh.jytid 
        and  jyt.ph = tqpd.ph
        and jyh.jyjg NOT LIKE '%#%' 
        and tqpd.tjsj > DATE_SUB(CURTIME(), INTERVAL 1.6 hour)  and tqpd.tjsj < DATE_SUB(CURTIME(), INTERVAL 0.5 hour) ) as jyh 

                """.format(**params)
        return sql_Zha_CaO_1